package net.sureon.biz;

import java.util.ArrayList;
import java.util.List;

import net.sureon.dao.Group;

/**
 * the group BIZ object.
 * 
 * @author jason
 */
public class GroupBO extends DefaultCategory implements CategoryAble {
    private Group groupVO;
    private List<GroupBO> childGroups = new ArrayList<GroupBO>();

    public GroupBO(Group groupVO) {
        this.groupVO = groupVO;
    }

    /**
     * @return the groupVO
     */
    public Group getGroupVO() {
        return groupVO;
    }

    public long getCompanyID() {
        return getGroupVO().getCompanyID();
    }

    public long getGroupID() {
        return getGroupVO().getGroupID();
    }

    public List<GroupBO> getChildGroups() {
        return childGroups;
    }

    public void addChildGroup(GroupBO group) {
        childGroups.add(group);
    }

    public List<Long> getDirectChildGroupManagers() {
        return getChildGroupManagers(1);
    }

    public List<Long> getChildGroupManagers(int level) {
        List<Long> list = new ArrayList<Long>();
        recusiveAddChildGroupManagers(list, level);
        return list;
    }

    private void recusiveAddChildGroupManagers(List<Long> list, int level) {
        if (level <= 0) {
            return;
        }
        long manager;
        for (GroupBO cg : childGroups) {
            manager = cg.getGroupVO().getGroupManager();
            if (manager > 0) {
                list.add(manager);
            }
            cg.recusiveAddChildGroupManagers(list, level - 1);
        }
    }
}
